class Solution
{
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration)
    {
        int ret = 0;
        vector<int> dp(timeSeries.size() - 1);
        for (int i = 0; i < timeSeries.size() - 1; i++)
        {
            dp[i] = timeSeries[i + 1] - timeSeries[i];
            if (dp[i] >= duration)
            {
                ret += duration;
            }
            else
            {
                ret += dp[i];
            }
        }
        ret += duration;
        return ret;
    }
};